13. Solutions: CAST

CAST Solutions

  1. SELECT *
    FROM sf_crime_data
    LIMIT 10;
  2. yyyy-mm-dd

  3. The format of the date column is mm/dd/yyyy with times that are not correct also at the end of the date.

  4. 4.
SELECT date orig_date, (SUBSTR(date, 7, 4) || '-' || LEFT(date, 2) || '-' || SUBSTR(date, 4, 2)) new_date
FROM sf_crime_data;
  1. Notice, this new date can be operated on using DATE_TRUNC and DATE_PART in the same way as earlier lessons.
SELECT date orig_date, (SUBSTR(date, 7, 4) || '-' || LEFT(date, 2) || '-' || SUBSTR(date, 4, 2))::DATE new_date
FROM sf_crime_data;

Code

If you need a code on the https://github.com/udacity.